<?
	require "view/objects/news.class.php";
	$news 		= new news();
	$menuleftHD		= $news->GetLeftMenuHD();
	$menuleftDC		= $news->GetLeftMenuDC("");
	$menuleftmovie	= $news->GetLeftMenuMovie();
	$hotnews		= $news->GetListNewsHot();
	
	$p			= intval($m[2]);
	global $pub,$sql;
	$action=PATH_HTTP.'Gio-hang/';
	if($m[1]=="DEL"){
		unset($_SESSION['ordercat'][$p]);
		$html = $pub->direct("".PATH_HTTP."Gio-hang/","Đơn hàng đã được xoá thành công");	
	}
	else{
		if($p!=""){
			$_SESSION['ordercat'][$p]	= $_SESSION['ordercat'][$p]+1;							
		}
		$html .='<div class="prod_box_big">
				<div class="top_prod_box_big"></div>
				<div class="center_prod_box_big"> ';
		$html .='<table border="1" cellpadding="0" cellspacing="0" style=" border-color:#CCCCCC;width:670px" align="center">';
	
		$html .= '<tr  bgcolor="#006699">
					<td align="center" width="30px" style="color:white; font-size:13px; font-weight:bold;">STT</td>
					<td align="center" width="100px"  style="color:white;font-size:13px; font-weight:bold;">Tên sản phẩm</td>
					<td align="center" width="80px"  style="color:white;font-size:13px; font-weight:bold;">Ảnh</td>				
					<td align="center" width="90"  style="color:white;font-size:13px; font-weight:bold;">Số lượng</td>
					<td align="center" width="90"  style="color:white;font-size:13px; font-weight:bold;">Đơn giá</td>
					<td align="center" width="90"  style="color:white;font-size:13px; font-weight:bold;">Thành tiền</td>					
					<td  align="center"  style="color:white;font-size:13px;font-weight:bold;">Xoá</td>
				</tr>';		
		$price = 0;
		$soluong=0;
	if (count($_SESSION['ordercat'])>0)  {
		$i = 1;
			foreach($_SESSION['ordercat'] as $key=>$value) {
				$result = $sql->query("SELECT * FROM product WHERE pro_id='".$key."'");	
				$rows 	=  $sql->fetch_array($result);
				$giaban = $rows["pro_price"]+0;
				$title	= $pub->CutStr($rows['pro_title']);
				$sl[$i]	= isset($_REQUEST['txtsl_'.$i])? $_REQUEST['txtsl_'.$i]:"1";
				if($rows['pro_bigimg']!=""){
						$img	= $rows['pro_bigimg'];
				}else{
						$img	= $rows['pro_smallimg'];							
				}				
				$html  .= '<tr>
							<td align="center">' . $i . '</td>
							<td><a href="'.PATH_HTTP.'Product/Detail/'.$rows['sub_id'].'/'.$rows['pro_id'].'/'.$title.'.html" style="color:blue; text-decoration:none; font-size:12px;">&nbsp;' . $rows['pro_title'] . '</a></td>
							<td align="center"><a href="'.PATH_HTTP.'upload_img/product/'.$img.'"  onclick="return hs.expand(this)"><img src="'.PATH_HTTP.'upload_img/product/'.$rows['pro_smallimg']. '" border="0" width="100px" ></a></td>				
							<td align="center"><input type="text" value="'.$sl[$i].'" name="txtsl_'.$i.'" size="3" style="text-align:center; font-weight:bold;"></td>
							<td align="center">'.$pub->StrMoney($giaban).'</td>
							<td align="center">'.$pub->StrMoney($rows['pro_price']*$sl[$i]+0).'</td>
							<td align="center"><a href="'.PATH_HTTP.'Cart/DEL/'.$rows['pro_id'].'/"><img src="'.PATH_HTTP.'image/delete.gif" border="0"></a></td>
						</tr>';	
				$price = $price+$rows['pro_price']*$sl[$i];
				$soluong=$soluong+$sl[$i];
			if($_REQUEST['Send']!=""){
				$sl[$i]		= $_REQUEST['txtsl_'.$i];
				$fullname	= $_REQUEST['re_name'];
				$email		= $_REQUEST['re_email'];
				$address	= $_REQUEST['re_address'];
				$tel		= $_REQUEST['re_tel'];
				$dateadd	= date("Y/m/d H:i");
				$content	= $_REQUEST['re_content'];
				$bill		= "NV-".date("YHs");
				$price		= $rows['pro_price']*$sl[$i];
				$result2	= $sql->query("INSERT INTO orders( `bill`, `fullname`, `email`, `address`, `tel`, `note`, `pro_id`, `pro_title`, `pro_quantity`, `pro_totalmoney`, `dateadd`, status) 
														VALUES ('".$bill."','".$fullname."','".$email."', '".$address."', '".$tel."','".$content."','".$rows['pro_id']."','".$rows['pro_title']."', '".$sl[$i]."', '".$price."', '".date("Y-m-d")."', '1')");
				if($result2!=""){
/////
					//Send mail
				$to 		= $pub->GetConfig("email_company");
				$from 		= $email;
				$title 		= "THÔNG TIN ĐẶT MUA TẠI WEB hd308.com";	
					
				$Headers="From:".$from."\n";
				$Headers.="Reply-To:".$from."\n";			
				$Headers.="Content-Type: text/html; charset=\"UTF-8\"; boundary=\"MIME_BOUNDRY\"\n";
				$Headers.="X-Sender:".$title."\n";
				$Headers.="X-Mailer: PHP5\n"; 
				$Headers.="X-Priority: 3\n"; 
				$Headers.="Return-Path:".$from."\n";
				$Subject = $title;
					
				$content .= "============== THÔNG TIN ĐƠN HÀNG =====================<br />
							Tên sản phẩm : ".$rows['pro_title']."<BR>
							Số lượng : ".$sl[$i]."
							".FULLNAME." : ".$fullname." :<br>
							".EMAIL." : ".$email."<br>
							".TEL." : ".$tel."<br>
							".ADDRESS." : ".$address."<br>
							".EMAIL." : ".$email."<br>
							<a href='".WEBSITE."'>".WEBSITE."</a><br>				
							".addslashes($content)."							
							===========================================================<br />";
				
				$content.= date('d-m-y H:i')."<br />";
				
				if(mail($to,$Subject,$content,$Headers)) {											
						$str = $pub->direct("".PATH_HTTP."","Đặt hàng thành công");
						unset($_SESSION['ordercat']);
					}else{
						$str = $pub->direct("".PATH_HTTP."","Đặt hàng thành công");
						unset($_SESSION['ordercat']);					
					}
				 }
			 }		
			 $i++;		
			}	
			
			
				$html .= '<tr>
							<td colspan="5" height="30" align="right" ><b>Tổng cộng : </b></td>
							<td align="right" >&nbsp;<b>'.$pub->StrMoney($price).'</b></td>
						</tr>';				
		}	
	
		$html .= '<tr>
					<td align="center" colspan="7" height="40"><div align="right">
					<input type="button" value="Tiếp tục mua hàng" onclick="javascript:location.href=\''.PATH_HTTP.'\'">
					<input type="submit" name="Update" value="Cập nhật giỏ hàng" >
					</td>
				</tr>';	
	
		$html .='</table></div>	<div class="bottom_prod_box_big"></div></div>';

}
?>